#import "UIBarButtonItem+item.h"
@implementation UIBarButtonItem (item)
+ (UIBarButtonItem *)itemWithImage:(NSString *)imageName hightImage:(NSString *)hightimgName target:(id)target action:(SEL)action
{
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn setImage:[UIImage imageNamed:imageName]forState:UIControlStateNormal];
    [btn setImage:[UIImage imageNamed:hightimgName] forState:UIControlStateHighlighted];
    [btn sizeToFit];
    [btn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    UIView *view = [[UIView alloc]initWithFrame:btn.bounds];
    [view addSubview:btn];
    return [[UIBarButtonItem alloc]initWithCustomView:view];
}
+ (UIBarButtonItem *)backItemWithImage:(NSString *)imageName hightImage:(NSString *)hightimgName target:(id)target action:(SEL)action title:(NSString *)title
{
    UIButton *backBtn = [UIButton buttonWithType:UIButtonTypeCustom];
    [backBtn setTitle:title forState:UIControlStateNormal];
    [backBtn setImage:[UIImage imageNamed:imageName] forState:UIControlStateNormal];
    [backBtn setImage:[UIImage imageNamed:hightimgName] forState:UIControlStateHighlighted];
    [backBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [backBtn setTitleColor:[UIColor redColor] forState:UIControlStateHighlighted];
    [backBtn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    backBtn.contentEdgeInsets = UIEdgeInsetsMake(0, -10, 0, 0);
    [backBtn sizeToFit];
    return  [[UIBarButtonItem alloc]initWithCustomView:backBtn];
}
+ (UIBarButtonItem *)itemWithImage:(NSString *)imageName selImage:(NSString *)selimgName target:(id)target action:(SEL)action
{
    UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
    [btn setImage:[UIImage imageNamed:imageName]forState:UIControlStateNormal];
    [btn setImage:[UIImage imageNamed:selimgName] forState:UIControlStateSelected];
    [btn sizeToFit];
    [btn addTarget:target action:action forControlEvents:UIControlEventTouchUpInside];
    UIView *view = [[UIView alloc]initWithFrame:btn.bounds];
    [view addSubview:btn];
    return [[UIBarButtonItem alloc]initWithCustomView:view];
}
@end
